//
//  SunOptionVC.m
//  Xspcf
//
//  Created by sunshine on 16/10/28.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunOptionVC.h"
#import "SunForgetCodeVC.h"
#import "SunChangePayCodeVC.h"
#import "SunGesSetVC.h"
#import "SunGesChangeVC.h"
#import "SunAddressVc.h"
#import "SunOpenBindVC.h"
#import "JxWebVC.h"
#import "SunBankDetailVC.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "SunDelegateWebVC.h"
#import "SunWebVC.h"

@interface SunOptionVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tb;
    NSMutableArray *_dataArr;
    UISwitch *_ges;
    UISwitch *_finger;
    int _canUseTouchId;
    NSTimer *_timer;
    int _openTouchId;
    NSArray *_addressArr;
    NSDictionary *_user;
}
@end

@implementation SunOptionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"安全中心";
    self.view.backgroundColor = BACKGROUND;
    [self initData];
    [self creatUI];
    // Do any additional setup after loading the view.
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (_timer) {
        [_timer invalidate];
        _timer = nil;
    }
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"IsSetGesture"]) {
        _ges.on = YES;
        _dataArr = [NSMutableArray arrayWithArray:@[@[@{@"img":@"third_option_1",@"title":@"绑定手机"},@{@"img":@"third_option_2",@"title":@"银行存管"},@{@"img":@"third_option_3",@"title":@"银行卡"},@{@"img":@"third_option_11",@"title":@"收货地址"},@{@"img":@"third_risk",@"title":@"风险测评"}],@[@{@"img":@"third_option_4",@"title":@"修改登录密码"},@{@"img":@"third_option_5",@"title":@"修改支付密码"},@{@"img":@"third_option_13",@"title":@"忘记支付密码"},@{@"img":@"third_option_6",@"title":@"指纹解锁"},@{@"img":@"third_option_7",@"title":@"手势密码"},@{@"img":@"third_option_8",@"title":@"修改手势密码"}],@[@{@"img":@"third_option_9",@"title":@"清除缓存"},@{@"img":@"third_option_10",@"title":@"接收消息推送"}]]];
    }else{
        _ges.on = NO;
        _dataArr = [NSMutableArray arrayWithArray:@[@[@{@"img":@"third_option_1",@"title":@"绑定手机"},@{@"img":@"third_option_2",@"title":@"银行存管"},@{@"img":@"third_option_3",@"title":@"银行卡"},@{@"img":@"third_option_11",@"title":@"收货地址"},@{@"img":@"third_risk",@"title":@"风险测评"}],@[@{@"img":@"third_option_4",@"title":@"修改登录密码"},@{@"img":@"third_option_5",@"title":@"修改支付密码"},@{@"img":@"third_option_13",@"title":@"忘记支付密码"},@{@"img":@"third_option_6",@"title":@"指纹解锁"},@{@"img":@"third_option_7",@"title":@"手势密码"}],@[@{@"img":@"third_option_9",@"title":@"清除缓存"},@{@"img":@"third_option_10",@"title":@"接收消息推送"}]]];
    }
    LAContext* context = [[LAContext alloc] init];
    NSError *error;
    [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
    _canUseTouchId = (int)error.code;
    [self requestToAddress];
    [self requestToUser];
    [_tb reloadData];
}

- (void)initData{
    _user = [Sun getUser:USER];
    _dataArr = [NSMutableArray arrayWithArray:@[@[@{@"img":@"third_option_1",@"title":@"绑定手机"},@{@"img":@"third_option_2",@"title":@"银行存管"},@{@"img":@"third_option_3",@"title":@"银行卡"},@{@"img":@"third_option_11",@"title":@"收货地址"},@{@"img":@"third_risk",@"title":@"风险测评"}],@[@{@"img":@"third_option_4",@"title":@"修改登录密码"},@{@"img":@"third_option_5",@"title":@"修改支付密码"},@{@"img":@"third_option_13",@"title":@"忘记支付密码"},@{@"img":@"third_option_6",@"title":@"指纹解锁"},@{@"img":@"third_option_7",@"title":@"手势密码"}],@[@{@"img":@"third_option_9",@"title":@"清除缓存"},@{@"img":@"third_option_10",@"title":@"接收消息推送"}]]];
}

- (void)creatUI{
    _tb = [[UITableView alloc]initWithFrame:CGRectNull style:UITableViewStyleGrouped];
    _tb.delegate = self;
    _tb.dataSource = self;
    [self.view addSubview:_tb];
    _tb.backgroundColor = BACKGROUND;
    _tb.showsVerticalScrollIndicator = NO;
    [_tb lt_All:SunEdgesMake(0, 0, 0, 0) save:YES];
}

- (void)setGesture:(UISwitch *)swich{
    if (swich.on) {
        SunGesSetVC *vc = [[SunGesSetVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"IsSetGesture"];
        _dataArr = [NSMutableArray arrayWithArray:@[@[@{@"img":@"third_option_1",@"title":@"绑定手机"},@{@"img":@"third_option_2",@"title":@"银行存管"},@{@"img":@"third_option_3",@"title":@"银行卡"},@{@"img":@"third_option_11",@"title":@"收货地址"},@{@"img":@"third_risk",@"title":@"风险测评"}],@[@{@"img":@"third_option_4",@"title":@"修改登录密码"},@{@"img":@"third_option_5",@"title":@"修改支付密码"},@{@"img":@"third_option_13",@"title":@"忘记支付密码"},@{@"img":@"third_option_6",@"title":@"指纹解锁"},@{@"img":@"third_option_7",@"title":@"手势密码"}],@[@{@"img":@"third_option_9",@"title":@"清除缓存"},@{@"img":@"third_option_10",@"title":@"接收消息推送"}]]];
        [_tb reloadData];
    }
}

- (void)onTimer{
    if (_openTouchId == 0) {
        return;
    }else if (_openTouchId == 1) {
        _finger.on = YES;
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:kusetouchid];
    }else {
        _finger.on = NO;
        [[NSUserDefaults standardUserDefaults]setBool:NO forKey:kusetouchid];
    }
    _openTouchId = 0;
    [_timer invalidate];
    _timer = nil;
}

- (void)changeTouchId{
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
    if (_finger.on == NO) {
        _finger.on = NO;
        [[NSUserDefaults standardUserDefaults]setBool:NO forKey:kusetouchid];
    }else{
        if (_canUseTouchId == 0) {
            LAContext* context = [[LAContext alloc] init];
            NSString* result = @"请按Home验证指纹";
            [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
                if (success) {
                    _openTouchId = 1;
                }
                else {
                    _openTouchId = 2;
                }
            }];
        }else {
            NSString *str;
            if (_canUseTouchId == -8) {
                str = @"由于指纹错误次数过多，Touch ID功能暂时被锁定。";
            }else {
                str = @"您的设备没有录入指纹，请先在本机中录入指纹后，尝试开启此功能。";
            }
            [[Sun shareSun]alertAlign:NSTextAlignmentLeft title:@"温馨提示" content:str left:@"知道了" right:nil cancel:^{
                [[Sun shareSun]hideShow];
            } sure:nil To:self];
            _finger.on = NO;
            [[NSUserDefaults standardUserDefaults]setBool:NO forKey:kusetouchid];
        }
    }
}

- (void)getOut{
    [[Sun shareSun]alertAlign:NSTextAlignmentCenter title:@"温馨提示" content:@"确定退出登录吗？" left:@"确定" right:@"取消" cancel:^{
        [Sun setUser:@"0" forKey:KLOGIN];
        [Sun setUser:nil forKey:USER];
        [Sun setUser:nil forKey:MD5];
        [Sun setUser:nil forKey:DES];
        [Sun setUser:nil forKey:ACCESSID];
        [self.navigationController popToRootViewControllerAnimated:YES];
    } sure:^{
        [[Sun shareSun]hideShow];
    } To:self];
}

- (long long)fileSizeAtPath:(NSString *)filePath{
    NSFileManager *manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
    }
    return 0;
}

- (float)folderSizeAtPath:(NSString *)folderPath{
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]){
        return 0;
    }
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString *fileName;
    long long folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil){
        NSString *fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        folderSize += [self fileSizeAtPath:fileAbsolutePath];
    }
    folderSize += [[SDImageCache sharedImageCache] getSize];
    return folderSize / (1024.0 * 1024.0);
}

- (void)clearCache {
    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    
    NSArray *array = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
    for (NSString *p in array) {
        NSError *error;
        NSString *path = [cachPath stringByAppendingPathComponent:p];
        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
            [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
        }
    }
}

#pragma mark request
- (void)requestToAddress{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_GETADDRESS];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        _addressArr = requestDic;
        [_tb reloadData];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun] showMsg:errorInfo];
    }];
}

- (void)requestToUser{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_USERINFO];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [Sun setUser:requestDic forKey:USER];
        _user = requestDic;
        [_tb reloadData];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

#pragma mark tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataArr[section]count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return Y(54);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return Y(45);
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == _dataArr.count - 1) {
        return Y(180);
    }
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    UILabel *label = [[UILabel alloc]init];
    [view addSubview:label];
    [label lt_setLeft:X(20) to:nil save:YES];
    [label lt_setBottom:Y(10) to:nil save:YES];
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:14];
    if (section == 0) {
        label.text = @"个人信息";
    }
    if (section == 1) {
        label.text = @"密码保护";
    }
    if (section == 2) {
        label.text = @"通用";
    }
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == _dataArr.count - 1) {
        UIView *view = [[UIView alloc]init];
        UILabel *label = [[UILabel alloc]init];
        [view addSubview:label];
        [label lt_setTop:Y(10) to:nil save:YES];
        [label lt_setLeft:X(21) to:nil Right:X(21) to:nil save:YES];
        label.numberOfLines = 0;
        label.preferredMaxLayoutWidth = SCREENWIDTH - X(42);
        label.textColor = GRAY;
        label.font = [UIFont systemFontOfSize:14];
        label.text = @"如果你想要关闭或者开启推送功能，请在手机的“设置-通知中心”中找到“小算盘”更改。";
        UIButton *btn = [[UIButton alloc]init];
        [view addSubview:btn];
        [btn lt_setTop:Y(36) to:label save:YES];
        [btn lt_XcenterTo:nil save:YES];
        [btn lt_setSize:CGSizeMake(X(333), Y(44)) save:YES];
        btn.clipsToBounds = YES;
        [btn setBackgroundColor:RED forState:UIControlStateNormal];
        [btn setBackgroundColor:[HXColor colorWithHexString:@"df3951"] forState:UIControlStateHighlighted];
        btn.layer.cornerRadius = 4;
        [btn setTitle:@"退出登录" forState:UIControlStateNormal];
        [btn setTitleColor:WHITE forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:17];
        [btn addTarget:self action:@selector(getOut) forControlEvents:UIControlEventTouchUpInside];
        return view;
    }
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        UILabel *label = [[UILabel alloc]init];
        [cell addSubview:label];
        [label lt_YcenterTo:nil save:YES];
        [label lt_setRight:X(15) to:nil save:YES];
        label.textColor = GRAY;
        label.font = [UIFont systemFontOfSize:16];
        label.tag = 1;
        UILabel *label2 = [[UILabel alloc]init];
        [cell addSubview:label2];
        [label2 lt_YcenterTo:nil save:YES];
        [label2 lt_setRight:X(32) to:nil save:YES];
        label2.textColor = GRAY;
        label2.font = [UIFont systemFontOfSize:16];
        label2.tag = 3;
        UISwitch *swich = [[UISwitch alloc]init];
        [cell addSubview:swich];
        [swich lt_YcenterTo:nil save:YES];
        [swich lt_setRight:X(15) to:nil save:YES];
        swich.onTintColor = RED;
        swich.tag = 2;
    }
    UILabel *label = [cell viewWithTag:1];
    UILabel *label2 = [cell viewWithTag:3];
    UISwitch *swich = [cell viewWithTag:2];
    cell.imageView.image = [UIImage imageNamed:[_dataArr[indexPath.section][indexPath.row]objectForKey:@"img"]];
    cell.textLabel.text = [_dataArr[indexPath.section][indexPath.row]objectForKey:@"title"];
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    label.hidden = YES;
    label2.hidden = YES;
    swich.hidden = YES;
    switch (indexPath.section) {
        case 0:{
            switch (indexPath.row) {
                case 0:{
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.accessoryType=UITableViewCellAccessoryNone;
                    label.hidden = NO;
                    label2.hidden = YES;
                    swich.hidden = YES;
                    NSString *phone = [_user objectForKey:@"phone"];
                    phone = [[[phone substringToIndex:3]stringByAppendingString:@"****"]stringByAppendingString:[phone substringFromIndex:7]];
                    label.text = phone;
                    break;
                }
                case 1:{
                    if ([[_user objectForKey:@"status"] intValue]==3) {
                        cell.selectionStyle = UITableViewCellSelectionStyleNone;
                        cell.accessoryType=UITableViewCellAccessoryNone;
                        label.hidden = NO;
                        label2.hidden = YES;
                        swich.hidden = YES;
                        label.text = [_user objectForKey:@"name"];
                    }else {
                        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                        label.hidden = YES;
                        label2.hidden = NO;
                        swich.hidden = YES;
                        label2.text = @"去开通";
                    }
                    break;
                }
                case 2:{
                    if ([[_user objectForKey:@"status"] intValue] == 3) {
                        cell.selectionStyle = UITableViewCellSelectionStyleNone;
                        cell.accessoryType=UITableViewCellAccessoryNone;
                        label.hidden = NO;
                        label2.hidden = YES;
                        swich.hidden = YES;
                        if ([[_user objectForKey:@"bankCard"] length] >=4) {
                            label.text = [NSString stringWithFormat:@"%@(%@)",[_user objectForKey:@"bank"],[[_user objectForKey:@"bankCard"] substringFromIndex:[[_user objectForKey:@"bankCard"]length] - 4]];
                        }else{
                            
                        }
                    }else {
                        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                        label.hidden = YES;
                        label2.hidden = NO;
                        swich.hidden = YES;
                        label2.text = @"去绑定";
                    }
                    break;
                }
                case 3:{
                    label.hidden = YES;
                    label2.hidden = NO;
                    swich.hidden = YES;
                    if (_addressArr && _addressArr.count > 0) {
                        label2.text = @"去修改";
                    }else {
                        label2.text = @"去设置";
                    }
                    break;
                }
                case 4:{
                    label.hidden = YES;
                    label2.hidden = NO;
                    swich.hidden = YES;
                    if ([[_user objectForKey:@"isRisk"] intValue] == 0) {
                        label2.text = @"去评估";
                    }else {
                        label2.text = [_user objectForKey:@"risk"];
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 1:{
            switch (indexPath.row) {
                case 0:{
                    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = YES;
                    break;
                }
                case 1:{
                    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = YES;

                    cell.textLabel.text = @"修改支付密码";
                    break;
                }
                case 2:{
                    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = YES;
                    cell.textLabel.text = @"忘记支付密码";
                    break;
                }
                case 3:{
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.accessoryType=UITableViewCellAccessoryNone;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = NO;
                    if ([[NSUserDefaults standardUserDefaults] boolForKey:kusetouchid]) {
                        swich.on = YES;
                    }else{
                        swich.on = NO;
                    }
                    [swich addTarget:self action:@selector(changeTouchId) forControlEvents:UIControlEventValueChanged];
                    _finger = swich;
                    break;
                }
                case 4:{
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.accessoryType=UITableViewCellAccessoryNone;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = NO;
                    [swich addTarget:self action:@selector(setGesture:) forControlEvents:UIControlEventValueChanged];
                    _ges = swich;
                    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"IsSetGesture"]) {
                        _ges.on = YES;
                    }else{
                        _ges.on = NO;
                        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"IsSetGesture"];
                    }
                    break;
                }
                case 5:{
                    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                    label.hidden = YES;
                    label2.hidden = YES;
                    swich.hidden = YES;
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 2:{
            switch (indexPath.row) {
                case 0:{
                    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
                    label.hidden = YES;
                    label2.hidden = NO;
                    swich.hidden = YES;
                    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
                    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
                    float singleSize = [self folderSizeAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
                    label2.text = [NSString stringWithFormat:@"%.2fM", singleSize * files.count / 10];
                    break;
                }
                case 1:{
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.accessoryType=UITableViewCellAccessoryNone;
                    label.hidden = NO;
                    label2.hidden = YES;
                    swich.hidden = YES;
                    if ( [[UIApplication sharedApplication] currentUserNotificationSettings].types == UIUserNotificationTypeNone){
                        label.text = @"已关闭";
                    }else {
                        label.text = @"已开启";
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *dic = [Sun getUser:USER];
    switch (indexPath.section) {
        case 0:{
            switch (indexPath.row) {
                case 0:{
                    break;
                }
                case 1:{
                    if ([[_user objectForKey:@"status"] intValue]==3) {
                    }else {
                        SunOpenBindVC *vc = [[SunOpenBindVC alloc]init];
                        [self.navigationController pushViewController:vc animated:YES];
                    }
                    break;
                }
                case 2:{
                    if ([[_user objectForKey:@"status"] intValue] == 3) {
                    }else {
                        SunOpenBindVC *vc = [[SunOpenBindVC alloc]init];
                        [self.navigationController pushViewController:vc animated:YES];
                    }
                    break;
                }
                case 3:{
                    SunAddressVc *vc = [[SunAddressVc alloc]init];
                    vc.addressArr = _addressArr;
                    [self.navigationController pushViewController:vc animated:YES];
                    break;
                }
                case 4:{
                    SunWebVC *vc = [[SunWebVC alloc]init];
                    NSString *str = @"CZfSDQzsuDayjfzE";
                    NSString *str1 =@"12345678";
                    NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
                    NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
                    vc.urlStr = [NSString stringWithFormat:@"%@/account/risk_evaluation?source=ios&token_id=%@&sign=%@",KWAP,token_id,md5Str];
                    vc.titleName = @"风险测评";
                    [self.navigationController pushViewController:vc animated:YES];                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 1:{
            switch (indexPath.row) {
                case 0:{
                    SunForgetCodeVC *vc = [[SunForgetCodeVC alloc]init];
                    vc.phone = [[Sun getUser:USER] objectForKey:@"phone"];
                    [self.navigationController pushViewController:vc animated:YES];
                    break;
                }
                case 1:{
                    if ([[_user objectForKey:@"status"] intValue]==3) {
                        NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_PASSWORD];
                        [[Sun shareSun]showActivity:self];
                        SunDelegateWebVC *vc = [[SunDelegateWebVC alloc]init];
                        NSString *type = @"1";
                        vc.title = @"修改支付密码";
                        type = @"1";
                        NSDictionary *param = @{@"device":@"iOS",@"type":type};
                        NSString *str = [Sun stringFromDictionary:(NSDictionary *)param];
                        vc.params = str;
                        vc.urlStr = url;
                        [self.navigationController pushViewController:vc animated:YES];
                    }else {
                        SunOpenBindVC *vc = [[SunOpenBindVC alloc]init];
                        [self.navigationController pushViewController:vc animated:YES];
                    }
                    break;
                }
                case 2:{
                    if ([[_user objectForKey:@"status"] intValue] == 3) {
                        NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_PASSWORD];
                        [[Sun shareSun]showActivity:self];
                        SunDelegateWebVC *vc = [[SunDelegateWebVC alloc]init];
                        NSDictionary *param = @{@"device":@"iOS",@"type":@"0"};
                        NSString *str = [Sun stringFromDictionary:(NSDictionary *)param];
                        vc.params = str;
                        vc.urlStr = url;
                        vc.title = @"忘记支付密码";
                        [self.navigationController pushViewController:vc animated:YES];
                    }else {
                        SunOpenBindVC *vc = [[SunOpenBindVC alloc]init];
                        [self.navigationController pushViewController:vc animated:YES];
                    }
                    
                    break;
                }
                case 3:{
                    break;
                }
                case 4:{
                    SunGesChangeVC *vc = [[SunGesChangeVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 2:{
            switch (indexPath.row) {
                case 0:{
                    [[Sun shareSun]alertAlign:NSTextAlignmentCenter title:@"温馨提示" content:@"是否确认清除缓存？" left:@"确定" right:@"取消" cancel:^{
                        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                        UILabel *label = [cell viewWithTag:3];
                        [self clearCache];
                        [[Sun shareSun]showMsg:@"缓存已清除"];
                        label.text = @"0.00M";
                        [[Sun shareSun]hideShow];
                    } sure:^{
                        [[Sun shareSun]hideShow];
                    } To:self];
                    break;
                }
                case 1:{
                    break;
                }
                default:
                    break;
            }
            break;
        }
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
